import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { clearError } from 'actions/app';

class AppContainer extends Component {
  componentWillMount() {
    this.test = 'test';
  }
  render() {
    const { dispatch, error } = this.props;
    return (
      <div>
        {this.props.children}
        <div
          className={`errorMsg${error ? ' --show' : ''}`}
          onAnimationEnd={() => dispatch(clearError())}
        >{error}</div>
      </div>
    );
  }
}

AppContainer.propTypes = {
  dispatch: PropTypes.func,
  children: PropTypes.element,
  error: PropTypes.string,
};

function mapStateToProps(state) {
  return {
    error: state.app.error,
  };
}
export default connect(mapStateToProps)(AppContainer);
